import { User } from 'src/users/entities/user.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToMany,
} from 'typeorm';

@Entity({ name: 'tb_roles' })
export class Role {
  @PrimaryGeneratedColumn('increment', {
    name: 'role_id',
    type: 'bigint',
    comment: '角色ID 主键',
    primaryKeyConstraintName: 'role_id',
  })
  role_id: number;

  @Column({
    name: 'role_name',
    type: 'varchar',
    length: 255,
    unique: true,
    nullable: true,
    comment: '角色名称（唯一）',
  })
  role_name: string;

  @Column({
    name: 'description',
    type: 'text',
    nullable: true,
    comment: '角色描述',
  })
  description: string;

  @Column({
    name: 'is_system',
    type: 'bool',
    default: false,
    comment: '是否是系统内置角色，1-是，0-否，默认否',
  })
  is_system: boolean;

  @ManyToMany(() => User)
  users: User[];

  @UpdateDateColumn({
    name: 'updated_at',
    type: 'timestamp',
    comment: '最后一次更新时间',
  })
  updated_at: number;

  @CreateDateColumn({
    name: 'created_at',
    type: 'timestamp',
    comment: '创建时间',
  })
  created_at: number;
}
